﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace House_Control
{
    //This class creates and stores Rooms, Alarms and a Thermostat. Basically, this class deals with all the meat of our program.
    class House
    {
        //These variables just store some owner information about the house.
        string address;
        string owner;
        string phoneNumber;

        //These variables store all of the things inside the house.
        Thermostat thermo;
        List<Room> rooms;
        public List<Alarm> alarms;
        public List<DoorAlarm> doorAlarms;
        public List<WindowAlarm> windowAlarms;
        public List<MotionAlarm> motionAlarms;
        public List<SmokeDetector> smokeAlarms;
        public List<FireAlarm> fireAlarms;
        public Boolean isArmed = false;
        //This variable is just sort of here... it doesn't really do anything.
        int noOfRooms;
        int noOfAlarms;
        //Associate a survelliance object
        public Survelliance survelliance = new Survelliance();
        
        
        public House()
        {
            address = " 307 Peg-Wen Blvd. \n Statesboro, GA 30461";
            owner = "Matthew Helwig";
            phoneNumber = ""+9124895554;
            rooms = new List<Room>();
            alarms = new List<Alarm>();

            doorAlarms = new List<DoorAlarm>();
            windowAlarms = new List<WindowAlarm>();
            motionAlarms = new List<MotionAlarm>();
            smokeAlarms = new List<SmokeDetector>();
            fireAlarms = new List<FireAlarm>();


            noOfRooms = 0;
            thermo = new Thermostat();
        }

        public void addRoom()
        {
            rooms.Add(new Room(noOfRooms));
        }

        public Room getRoom(int roomNo)
        {
            return rooms[roomNo];
        }
        /*
         * Begin Alarm Methods
         */
        public void addAlarm(int alarmType, int roomNo)
        {
            noOfAlarms++;
            switch (alarmType)
            {
                case 0: //Window
                    windowAlarms.Add(new WindowAlarm(roomNo));
                    alarms.Add(windowAlarms.LastOrDefault());
                    break;
                case 1: //Door
                    doorAlarms.Add(new DoorAlarm(roomNo));
                    alarms.Add(doorAlarms.LastOrDefault());
                    break;
                case 2: //Motion Detector
                    motionAlarms.Add(new MotionAlarm(roomNo));
                    alarms.Add(motionAlarms.LastOrDefault());
                    break;
                case 3: //Smoke Detector
                    smokeAlarms.Add(new SmokeDetector(roomNo));
                    alarms.Add(smokeAlarms.LastOrDefault());
                    break;
                case 4: //Fire Alarm
                    fireAlarms.Add(new FireAlarm(roomNo));
                    alarms.Add(fireAlarms.LastOrDefault());
                    break;
                default:
                    break;
            }
        }
        
        public Alarm getAlarm(int alarmNo)
        {
            return alarms[0];
        }
        public void armHouse()
        {
            for (int i = 0; i < noOfAlarms; i++)
                alarms[i].arm();
            isArmed = true;
        }
        public void disarmHouse()
        {
            for (int i = 0; i < noOfAlarms; i++)
                alarms[i].disarm();
            isArmed = false;
        }
        public void deactivateAlarms()
        {
            for (int i = 0; i < noOfAlarms; i++)
                alarms[i].deactivate();
        }

        public Boolean isTripped(int alarmType)
        {
            for(int i=0; i<noOfAlarms; i++)
            {
                if(alarms[i].getType()==alarmType&&alarms[i].tripped)
                return true;
            }
            return false;
        }
        public Boolean lowSmokeBat()
        {
            for (int i = 0; i < smokeAlarms.Count; i++)
            {
                if (smokeAlarms[i].lowBat)
                    return true;
            }
            return false;
        }

        public Thermostat getThermoStat()
        {
            return thermo;
        }

        /*
         * End Alarm Methods
         */
        public string getOwner()
        {
            return owner;
        }

        public string getAddress()
        {
            return address;
        }

        public string getPhoneNumber()
        {
            return phoneNumber;
        }

        public void setOwner(string newOwner)
        {
            owner = newOwner;
        }

        public void setAddress(string newAddress)
        {
            address = newAddress;
        }

        public void setPhoneNumber(string newPhoneNumber)
        {
            phoneNumber = newPhoneNumber;
        }

    }
}
